﻿using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using JYJ.AiYard.Authorization;
using JYJ.AiYard.StationManagement.TbDiscountBills.Authorization;
using JYJ.AiYard.StationManagement.TbYardIssuedCards.Authorization;

namespace JYJ.AiYard.StationManagement.YardReport.Authorization
{
    public class TbrInYardAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

        public TbrInYardAuthorizationProvider()
        {

        }

        public TbrInYardAuthorizationProvider(bool isMultiTenancyEnabled)
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public TbrInYardAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

        public override void SetPermissions(IPermissionDefinitionContext context)
        {            
            var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));
            //报表中心
            var administration = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Page_YardReport) ?? pages.CreateChildPermission(AppPermissions.Page_YardReport, L("YardReport"));

            var rOnlinePayPermissions = administration.CreateChildPermission(TbrInYardPermissions.TbrOnlinePayNode, L("TbrOnlinePay"));
            rOnlinePayPermissions.CreateChildPermission(TbrInYardPermissions.TbrOnlinePayQuery, L("QueryTbrOnlinePay"));
            rOnlinePayPermissions.CreateChildPermission(TbrInYardPermissions.TbrOnlinePayExportExcel, L("ExportExcelTbrOnlinePay"));

            var rInvoicePermissions = administration.CreateChildPermission(TbrInYardPermissions.TbrInvoiceNode, L("TbrInvoice"));
            rInvoicePermissions.CreateChildPermission(TbrInYardPermissions.TbrInvoiceQuery, L("QueryTbrInvoice"));
            rInvoicePermissions.CreateChildPermission(TbrInYardPermissions.TbrInvoiceExportExcel, L("ExportExcelTbrInvoice"));
            rInvoicePermissions.CreateChildPermission(TbrInYardPermissions.TbrInvoiceBatchDelete, L("BatchDeleteTbrInvoice"));

            var tInYardPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrInYardNode, L("TbrInYard"));
            tInYardPermission.CreateChildPermission(TbrInYardPermissions.TbrInYardQuery, L("QueryTbrInYard"));
            tInYardPermission.CreateChildPermission(TbrInYardPermissions.TbrInYardExportExcel, L("ExportExcelTbrInYard"));
            tInYardPermission.CreateChildPermission(TbrInYardPermissions.TbrInYardExportBatchDelete, L("BatchDeleteTbrInYard"));
            tInYardPermission.CreateChildPermission(TbrInYardPermissions.TbrInYardExportInYard, L("ExportTbrInYard"));

            var rOutYardPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrOutYardNode, L("TbrOutYard"));
            rOutYardPermission.CreateChildPermission(TbrInYardPermissions.TbrOutYardQuery, L("QueryTbrOutYard"));
            rOutYardPermission.CreateChildPermission(TbrInYardPermissions.TbrOutYardExportExcel, L("ExportExcelTbrOutYard")); 
            rOutYardPermission.CreateChildPermission(TbrInYardPermissions.TbrOutYardExportBatchDelete, L("BatchDeleteTbrOutYard"));
            rOutYardPermission.CreateChildPermission(TbrInYardPermissions.TbrOutYardExportBatchHide, L("BatchHideBAccountTbrOutYard"));
            //隐藏数据
            //rOutYardPermission.CreateChildPermission(TbYardIssuedCardPermissions.ShowDeleteCardNo, L("ShowDeleteTbrOutYard"));

            var rOutYardPermission2 = administration.CreateChildPermission(TbrInYardPermissions.TbrOutYardNode2, L("TbrOutYard2"));
            rOutYardPermission2.CreateChildPermission(TbrInYardPermissions.TbrOutYardQuery2, L("QueryTbrOutYard"));
            rOutYardPermission2.CreateChildPermission(TbrInYardPermissions.TbrOutYardExportExcel2, L("ExportExcelTbrOutYard"));
            rOutYardPermission2.CreateChildPermission(TbrInYardPermissions.TbrOutYardExportBatchDelete2, L("BatchDeleteTbrOutYard"));
            rOutYardPermission2.CreateChildPermission(TbrInYardPermissions.TbrOutYardExportBatchHide2, L("BatchHideBAccountTbrOutYard"));
            //隐藏数据
            //rOutYardPermission2.CreateChildPermission(TbYardIssuedCardPermissions.ShowDeleteCardNo, L("ShowDeleteTbrOutYard"));

            var rOpenGatePermission = administration.CreateChildPermission(TbrInYardPermissions.TbrOpenGateNode, L("TbrOpenGate"));
            rOpenGatePermission.CreateChildPermission(TbrInYardPermissions.TbrOpenGateQuery, L("QueryTbrOpenGate"));
            rOpenGatePermission.CreateChildPermission(TbrInYardPermissions.TbrOpenGateExportExcel, L("ExportExcelTbrOpenGate"));

            var rChangeClassPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrChangeClassNode, L("TbrChangeClass"));
            rChangeClassPermission.CreateChildPermission(TbrInYardPermissions.TbrChangeClassQuery, L("QueryTbrChangeClass"));
            rChangeClassPermission.CreateChildPermission(TbrInYardPermissions.TbrChangeClassExportExcel, L("ExportExcelTbrChangeClass"));

            var rChangeClassPermission2 = administration.CreateChildPermission(TbrInYardPermissions.TbrChangeClassNode2, L("TbrChangeClass2"));
            rChangeClassPermission2.CreateChildPermission(TbrInYardPermissions.TbrChangeClassQuery2, L("QueryTbrChangeClass"));
            rChangeClassPermission2.CreateChildPermission(TbrInYardPermissions.TbrChangeClassExportExcel2, L("ExportExcelTbrChangeClass"));

            var rStaticsPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrStaticsNode, L("TbrStatics"));
            rStaticsPermission.CreateChildPermission(TbrInYardPermissions.TbrStaticsQuery, L("QueryTbrStatics"));
            rStaticsPermission.CreateChildPermission(TbrInYardPermissions.TbrStaticsExportExcel, L("ExportExcelTbrStatics"));

            var rStaticsPermission2 = administration.CreateChildPermission(TbrInYardPermissions.TbrStaticsNode2, L("TbrStatics2"));
            rStaticsPermission2.CreateChildPermission(TbrInYardPermissions.TbrStaticsQuery2, L("QueryTbrStatics"));
            rStaticsPermission2.CreateChildPermission(TbrInYardPermissions.TbrStaticsExportExcel2, L("ExportExcelTbrStatics"));

            var rStaticsPermission3 = administration.CreateChildPermission(TbrInYardPermissions.TbrStaticsNode3, L("TbrStatics3"));
            rStaticsPermission3.CreateChildPermission(TbrInYardPermissions.TbrStaticsQuery3, L("QueryTbrStatics"));
            rStaticsPermission3.CreateChildPermission(TbrInYardPermissions.TbrStaticsExportExcel3, L("ExportExcelTbrStatics"));

            var rIssuedOpCardPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrIssuedOpCardNode, L("TbrIssuedOpCard"));
            rIssuedOpCardPermission.CreateChildPermission(TbrInYardPermissions.TbrIssuedOpCardQuery, L("QueryTbrIssuedOpCard"));
            rIssuedOpCardPermission.CreateChildPermission(TbrInYardPermissions.TbrIssuedOpCardExportExcel, L("ExportExcelTbrIssuedOpCard"));
            //隐藏数据
            //rIssuedOpCardPermission.CreateChildPermission(TbYardIssuedCardPermissions.ShowDeleteCardNo, L("ShowDeleteTbrOutYard"));

            var rIssuedPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrIssuedNode, L("TbrIssued"));
            rIssuedPermission.CreateChildPermission(TbrInYardPermissions.TbrIssuedQuery, L("QueryTbrIssued"));
            rIssuedPermission.CreateChildPermission(TbrInYardPermissions.TbrIssuedExportExcel, L("ExportExcelTbrIssued"));
            //隐藏数据
            //rIssuedPermission.CreateChildPermission(TbYardIssuedCardPermissions.ShowDeleteCardNo, L("ShowDeleteTbrOutYard"));

            var rDiscountPermission = administration.CreateChildPermission(TbrInYardPermissions.TbrDiscountNode, L("TbrDiscount"));
            rDiscountPermission.CreateChildPermission(TbrInYardPermissions.TbrDiscountQuery, L("QueryTbrDiscount"));
            rDiscountPermission.CreateChildPermission(TbrInYardPermissions.TbrDiscountExportExcel, L("ExportExcelTbrDiscount"));
            rDiscountPermission.CreateChildPermission(TbrInYardPermissions.TbrDiscountBatchDelete, L("BatchDeleteTbDiscountBill")); 

            var rRoadPayResultsPermission = administration.CreateChildPermission(TbrInYardPermissions.rRoadPayResultsNode, L("rRoadPayResults"));
            rRoadPayResultsPermission.CreateChildPermission(TbrInYardPermissions.rRoadPayResultsQuery, L("QueryRoadReport"));
            rRoadPayResultsPermission.CreateChildPermission(TbrInYardPermissions.rRoadPayResultsExportExcel, L("ExportExcelRoadReport"));
            rRoadPayResultsPermission.CreateChildPermission(TbrInYardPermissions.rRoadPayResultsDownload, L("DownloadRoadReport"));

            var rRoadbillInfosPermission = administration.CreateChildPermission(TbrInYardPermissions.rRoadbillInfosNode, L("rRoadbillInfos"));
            rRoadbillInfosPermission.CreateChildPermission(TbrInYardPermissions.rRoadbillInfosQuery, L("QueryRoadReport"));
            rRoadbillInfosPermission.CreateChildPermission(TbrInYardPermissions.rRoadbillInfosExportExcel, L("ExportExcelRoadReport"));
            rRoadbillInfosPermission.CreateChildPermission(TbrInYardPermissions.rRoadbillInfosDownload, L("DownloadRoadReport"));

            var rRoadStaggerPermission = administration.CreateChildPermission(TbrInYardPermissions.rRoadStaggerNode, L("rRoadStagger"));
            rRoadStaggerPermission.CreateChildPermission(TbrInYardPermissions.rRoadStaggerQuery, L("QueryRoadReport"));
            rRoadStaggerPermission.CreateChildPermission(TbrInYardPermissions.rRoadStaggerExportExcel, L("ExportExcelRoadReport"));
            rRoadStaggerPermission.CreateChildPermission(TbrInYardPermissions.rRoadStaggerDownload, L("DownloadRoadReport"));

            var rStatisticsCLPermission = administration.CreateChildPermission(TbrInYardPermissions.rStatisticsCLNode, L("rStatisticsCL"));
            rStatisticsCLPermission.CreateChildPermission(TbrInYardPermissions.rStatisticsCLQuery, L("QueryStatisticsCL"));
            rStatisticsCLPermission.CreateChildPermission(TbrInYardPermissions.rStatisticsCLExportExcel, L("ExportExcelStatisticsCL")); 
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AppConsts.LocalizationSourceName);
        }
    }
}
